package com.studysystem.repository;

import com.studysystem.entity.Course;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
    Page<Course> findByTitleContainingOrDescriptionContaining(String title, String description, Pageable pageable);
    List<Course> findByInstructorId(Long instructorId);
    List<Course> findByCategory(String category);
    
    @Query("SELECT c FROM Course c WHERE c.price = 0")
    List<Course> findFreeCourses();
    
    // @Query("SELECT c FROM Course c ORDER BY (SELECT AVG(r.rating) FROM CourseReview r WHERE r.course = c) DESC")
    // Page<Course> findTopRatedCourses(Pageable pageable);
} 